﻿using System;
using System.Collections.Specialized;
using System.Net;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent.UI.Elements;
using Terraria.Graphics;
using Terraria.Localization;
using Terraria.ModLoader.IO;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x020002A9 RID: 681
	internal class UIModManageItem : UIPanel
	{
		// Token: 0x06001B21 RID: 6945 RVA: 0x0042EDA4 File Offset: 0x0042CFA4
		public UIModManageItem(string displayname, string name, string version, string author, string downloads, string downloadsversion, string modloaderversion)
		{
			this.displayname = displayname;
			this.version = version;
			this.author = author;
			this.name = name;
			this.BorderColor = new Color(89, 116, 213) * 0.7f;
			this.dividerTexture = TextureManager.Load("Images/UI/Divider");
			this.Height.Set(90f, 0f);
			this.Width.Set(0f, 1f);
			base.SetPadding(6f);
			string text = string.Concat(new string[]
			{
				displayname,
				" ",
				version,
				" - by ",
				author,
				" - ",
				modloaderversion
			});
			this.modName = new UIText(text, 1f, false);
			this.modName.Left.Set(10f, 0f);
			this.modName.Top.Set(5f, 0f);
			base.Append(this.modName);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBMyPublishedModsStats", downloads, downloadsversion), 1f, false);
			uitextPanel.Width.Set(260f, 0f);
			uitextPanel.Height.Set(30f, 0f);
			uitextPanel.Left.Set(10f, 0f);
			uitextPanel.Top.Set(40f, 0f);
			uitextPanel.PaddingTop -= 2f;
			uitextPanel.PaddingBottom -= 2f;
			base.Append(uitextPanel);
			this.button2 = new UITextPanel<string>(Language.GetTextValue("tModLoader.MBUnpublish"), 1f, false);
			this.button2.CopyStyle(uitextPanel);
			this.button2.Width.Set(150f, 0f);
			this.button2.Left.Set(360f, 0f);
			this.button2.OnMouseOver += UICommon.FadedMouseOver;
			this.button2.OnMouseOut += UICommon.FadedMouseOut;
			this.button2.OnClick += this.Unpublish;
			base.Append(this.button2);
		}

		// Token: 0x06001B22 RID: 6946 RVA: 0x0042F004 File Offset: 0x0042D204
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			base.DrawSelf(spriteBatch);
			CalculatedStyle innerDimensions = base.GetInnerDimensions();
			Vector2 position = new Vector2(innerDimensions.X + 5f, innerDimensions.Y + 30f);
			spriteBatch.Draw(this.dividerTexture, position, null, Color.White, 0f, Vector2.Zero, new Vector2((innerDimensions.Width - 10f) / 8f, 1f), SpriteEffects.None, 0f);
		}

		// Token: 0x06001B23 RID: 6947 RVA: 0x000132A0 File Offset: 0x000114A0
		public override void MouseOver(UIMouseEvent evt)
		{
			base.MouseOver(evt);
			this.BackgroundColor = new Color(73, 94, 171);
			this.BorderColor = new Color(89, 116, 213);
		}

		// Token: 0x06001B24 RID: 6948 RVA: 0x0042C064 File Offset: 0x0042A264
		public override void MouseOut(UIMouseEvent evt)
		{
			base.MouseOut(evt);
			this.BackgroundColor = new Color(63, 82, 151) * 0.7f;
			this.BorderColor = new Color(89, 116, 213) * 0.7f;
		}

		// Token: 0x06001B25 RID: 6949 RVA: 0x0042F088 File Offset: 0x0042D288
		internal void Unpublish(UIMouseEvent evt, UIElement listeningElement)
		{
			if (ModLoader.modBrowserPassphrase == "")
			{
				Main.menuMode = 10015;
				Interface.enterPassphraseMenu.SetGotoMenu(10011);
				return;
			}
			Main.PlaySound(12, -1, -1, 1, 1f, 0f);
			try
			{
				ServicePointManager.Expect100Continue = false;
				string address = "http://javid.ddns.net/tModLoader/unpublishmymod.php";
				NameValueCollection values = new NameValueCollection
				{
					{
						"name",
						this.name
					},
					{
						"steamid64",
						ModLoader.SteamID64
					},
					{
						"modloaderversion",
						ModLoader.versionedName
					},
					{
						"passphrase",
						ModLoader.modBrowserPassphrase
					}
				};
				byte[] array = UploadFile.UploadFiles(address, null, values);
				string @string = Encoding.UTF8.GetString(array, 0, array.Length);
				ErrorLogger.LogModUnPublish(@string);
			}
			catch (Exception e)
			{
				ErrorLogger.LogModBrowserException(e);
			}
		}

		// Token: 0x0400184B RID: 6219
		public string name;

		// Token: 0x0400184C RID: 6220
		public string displayname;

		// Token: 0x0400184D RID: 6221
		public string version;

		// Token: 0x0400184E RID: 6222
		public string author;

		// Token: 0x0400184F RID: 6223
		private Texture2D dividerTexture;

		// Token: 0x04001850 RID: 6224
		private UIText modName;

		// Token: 0x04001851 RID: 6225
		private UITextPanel<string> button2;
	}
}
